<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script type="text/javascript" src="<?=JS_PATH?>jquery.min.js"></script>
    <script src="<?=ASSETS?>time/js/foundation-datepicker.js" type="text/javascript"></script>
    <script src="<?=ASSETS?>time/js/foundation-datepicker.zh-CN.js" type="text/javascript"></script>
    <script type="text/javascript" src="<?=ASSETS?>layer/layer.js"></script>
    <link href="<?=ASSETS?>time/css/foundation-datepicker.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="<?=ASSETS?>bootstrap/bootstrap.min.css" />
    <title>文章类型列表</title>
</head>
<script>

    $(function(){


        $("#add_type").click(function()
        {
            var type_name = $("#type_name").val();
            if(type_name=="")
            {
                return;
            }
            else
            {
                $("#form-one").submit();
            }
        });

        $("#search").click(function()
        {
            var type_name = $("#key_word").val();
            if(type_name=="")
            {
                return;
            }
            else
            {
                $("#form-two").submit();
            }
        });

        $("tr button").click(function()
        {
            var id =$(this).attr("id");
            var type_name_obj = $("#type_name_"+id);
            var type_name = type_name_obj.text();

            layer.prompt({title: '请输入新文章类型名称',shade:false,value:type_name, formType: 0}, function(text, index){

                var url = "<?=web_url('label/update_type',true)?>";
                $.post(url,{new_name:text,id:id},function(data,status){

                    type_name_obj.text(text);
                    layer.close(index);
                });
            });
        });

        $("#show_all").click(function(){


            location.href= "<?=web_url('article/type',true)?>";

        });



    });

</script>
<body>
<div class="container" style="margin-top: 3%">

    <div class="row">



        <div class="col-lg-12">


            <div class="row">

                <div class="form-group col-lg-4 form-inline">

                    <form id="form-one" method="post">
                        <input name="type" value="add" type="hidden" />
                        <input maxlength="10" id="type_name"  name="type_name" type="text" style="margin-left: 1%;" class="form-control input-sm" placeholder="新类型名称"/>
                        <button  id="add_type" type="button"  class="btn btn-primary btn-sm">新增类型</button>
                    </form>

                </div>
                <div class="col-lg-1">

                    <button  id="show_all" type="button"  class="btn btn-primary btn-sm">显示全部</button>
                </div>
                <div class="form-group col-lg-3 col-lg-offset-4 form-inline">
                    <form id="form-two" method="post">
                        <div class="form-group form-inline">
                            <input name="type" value="search" type="hidden" />
                            <input id="key_word" name="key_word" type="text" placeholder="文章标题/编号" class="form-control input-sm"/>&nbsp;
                            <button id="search" type="button"  class="btn btn-primary btn-sm">搜索</button>
                        </div>
                    </form>
                </div>

            </div>


            <table class="table table-hover table-responsive table-condensed">

                <thead>
                <tr>

                    <th>编号</th>
                    <th>类型名称</th>
                    <th>创建时间</th>
                    <th>操作</th>

                </tr>

                </thead>

                <tbody>
                <?php foreach ($types as $type):?>
                    <tr>
                        <td><?=$type->id?></td>
                        <td id="type_name_<?=$type->id?>"><?=$type->label_name?></td>
                        <td><?=$type->ctime?></td>
                        <td>
                            <button id="<?=$type->id?>" class="btn btn-xs btn-primary">修改名称</button>&nbsp;&nbsp;
                            <a href="<?=web_url('label/index?id='.$type->id,true)?>" class="btn btn-xs btn-danger">删除类型</a>
                        </td>
                    </tr>
                <?php endforeach;?>
                </tbody>

            </table>

        </div>
        <div class="col-lg-offset-9">

            <?=$links?>

        </div>

    </div>

</div>
</body>
</html>